package vn.com.vega.music.objects;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public class SongList {
	List<Integer> listSongId;
	List<Integer> listArtistId;
	public SongList(List<Song> listSong) {
		listArtistId = new ArrayList<Integer>();
		listSongId = new ArrayList<Integer>();
		for (Song song : listSong) {
			listSongId.add(Integer.valueOf(song.id));
			listArtistId.add(Integer.valueOf(song.artist_id));
		}
	}
	
	public void addSong(Song song) {
		if (listSongId == null) {
			listSongId = new ArrayList<Integer>();
		}
		if (listArtistId == null) {
			listArtistId = new ArrayList<Integer>();
		}
		listSongId.add(Integer.valueOf(song.id));
		listArtistId.add(Integer.valueOf(song.artist_id));
	}
	
	public String toJsonString() {
		if (listSongId == null) {
			return null;
		}
		try {
			JSONObject json = new JSONObject();
			JSONArray songList = new JSONArray();
			JSONArray artistList = new JSONArray();
			for (Integer songId : listSongId) {
				songList.put(songId.intValue());
			}
			for (Integer artistId: listArtistId) {
				artistList.put(artistId.intValue());
			}
			json.put("songIds", songList);
			json.put("artistIds", artistList);
			return json.toString();
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
		return null;
	}
}
